package com.examination.client.controller;


import com.examination.client.annotation.PassToken;
import com.examination.client.domian.dto.PushOrderDTO;
import com.examination.client.domian.dto.PushOrderVO;
import com.examination.client.service.PayService;
import com.examination.client.util.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/pay")
@Api(tags = "支付相关")
@CrossOrigin(origins = "*")
public class PayController {

    @Resource
    PayService payService;

    /**
     * 统一下单
     */
    @ApiOperation("下单")
    @ResponseBody
    @PostMapping(value = "/pushOrder")
    public Result<PushOrderVO> pushOrder(@RequestBody @Validated PushOrderDTO pushOrderDTO, HttpServletRequest request) {
        return Result.success(payService.pushOrder(pushOrderDTO,request));
    }


    @PassToken
    @ResponseBody
    @ApiOperation("支付回调")
    @PostMapping(value = "/callback/notify")
    public String callback(HttpServletRequest request, HttpServletResponse response) {
        return payService.callback(request);

    }



}
